
#include "../bsp/beep/bsp_beep.h"
#include "../bsp/clk/bsp_clk.h"
#include "../bsp/epit/bsp_epit.h"
#include "../bsp/epittimer/bsp_epittimer.h"
#include "../bsp/int/bsp_int.h"
#include "../bsp/led/bsp_led.h"

void EPIT2_HANDLER();
/*
 * @description	: main函数
 * @param 		: 无
 * @return 		: 无
 */
int main(void) {

  int_init();      /* 初始化中断(一定要最先调用！) */
  imx6u_clkinit(); /* 初始化系统时钟 			*/
  clk_enable();    /* 使能所有的时钟 			*/
  led_init();      /* 初始化led 			*/
  beep_init();
  EPIT_INIT(EPIT2_BASE, 0, 66000000 / 2);
  EPIT_GIC_EnableIRQ(EPIT2_IRQn);
  EPIT_IRQ_HANDLER(EPIT2_IRQn, (system_irq_handler_t)EPIT2_HANDLER, NULL);
  EPIT_ENABLED(EPIT2_BASE);
  // epit1_init(0, 66000000 / 2);
  
  while (1) {
  }

  return 0;
}

void EPIT2_HANDLER() {
  static unsigned char state = 0;

  state = !state;
  if (EPIT2->SR & (1 << 0)) /* 判断比较事件发生 */
  {
    led_switch(LED0, state); /* 定时器周期到，反转LED */
    // beep_switch(state);
  }

  EPIT2->SR |= 1 << 0; /* 清除中断标志位 */
}